<template>
  <div class="container">
    <el-card>
      <template #header>
        <span style="font-size: 22px; font-weight: 600; color: #409eff;">题目列表</span>
      </template>

      <!-- 操作按钮和过滤器 -->
      <n-flex justify="space-between" align="center" style="margin-bottom: 20px;">
        <n-flex :size="10">
          <el-button type="primary" :icon="Plus">创建</el-button>
          <el-button type="success" :icon="Plus">添加远程OJ题目</el-button>
        </n-flex>
        <n-flex :size="15" align="center">
          <el-input v-model="keyword" placeholder="输入关键词" :prefix-icon="Search" style="width: 200px;"/>
          <el-select v-model="filter1" placeholder="全部题目" style="width: 150px;">
            <el-option label="全部题目" value=""></el-option>
          </el-select>
          <el-select v-model="filter2" placeholder="全部题目" style="width: 150px;">
            <el-option label="全部题目" value=""></el-option>
          </el-select>
        </n-flex>
      </n-flex>

      <!-- 数据表格 -->
      <el-table :data="problemList" style="width: 100%" empty-text="暂无数据">
        <el-table-column prop="id" label="ID" width="100" align="center" />
        <el-table-column prop="displayId" label="展示ID" width="120" align="center" />
        <el-table-column prop="title" label="标题" />
        <el-table-column prop="author" label="作者" width="150" align="center" />
        <el-table-column prop="createdAt" label="创建时间" width="180" align="center" />
        <el-table-column prop="updatedBy" label="最近修改者" width="150" align="center" />
        <el-table-column prop="auth" label="权限" width="120" align="center" />
        <el-table-column label="Option" width="200" align="center">
          <template #default="scope">
            <el-button type="primary" text :icon="Edit">编辑</el-button>
            <el-button type="danger" text :icon="Delete">删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <n-flex justify="center" style="margin-top: 20px;">
        <el-pagination
          background
          layout="prev, pager, next,total, sizes"
          :total="total"
          :page-size="pageSize"
          :current-page="currentPage"
          @size-change="handleSizeChange"
          @current-change="handlePageChange"
        />
      </n-flex>
    </el-card>
  </div>
</template>

<script lang="ts" setup>
//import
import { ref } from 'vue';
import { Plus, Search, Edit, Delete } from '@element-plus/icons-vue';

//data
const keyword = ref('');
const filter1 = ref('');
const filter2 = ref('');
const problemList = ref();
const total = ref(0);
const pageSize = ref(10);
const currentPage = ref(1);

problemList.value=[
  {
    id: 1,
    displayId: 1,
    title: 'Problem 1',
    author: 'Author 1',
    createdAt: '2023-01-01 00:00:00',
    updatedBy: 'Author 1',
    auth: 'Public',
  },
  {
    id: 2,
    displayId: 2,
    title: 'Problem 2',
    author: 'Author 2',
    createdAt: '2023-01-02 00:00:00',
    updatedBy: 'Author 2',
    auth: 'Public',
  },
]

//methods
const handleSizeChange = (size: number) => {
  pageSize.value = size;
};
const handlePageChange = (page: number) => {
  currentPage.value = page;
};
</script>

<style scoped lang="css">
.container {
  padding: 20px;
}
</style>
